<?php


namespace app\api\controller\v16;


use app\api\controller\v13\Auth2;
use app\common\cachemodel\GoddessArea as GoddessAreaModel;
use app\common\cachemodel\GoddessBaseInfo;
use think\response\Json;

class GoddessArea extends Auth2
{
    /**
     * 女神专区
     * @return Json
     * @throws \Exception
     */
    public function index()
    {
        $page = input('page/d', 1);
        $limit = input('limit/d', 10);
        $uid = $this->user ? (int)$this->user['id'] : null;

        $goddessInfo = (new GoddessBaseInfo())->getInfo(['nickname', 'avatar', 'title2', 'notice_img2', 'target2', 'link2']);

        $goddessArea = (new GoddessAreaModel())->getThemeData($uid, $goddessInfo, $page, $limit);

        if ($page === 1)
        {
            // 幸运星按钮移动到女神专区，当用户开启青少年模式时，返回3禁止访问，否则返回2：验证登录，不验证档案
            $luckyNeedAuth = ($this->user && $this->user['young_model']) ? 3 : 2;

            if ($goddessInfo['notice_img2'])
            {
                $goddessArea['notice'] = [
                    'img' => $goddessInfo['notice_img2'] ?? '',
                    'target' => $goddessInfo['target2'] ?? '',
                    'link' => $goddessInfo['link2'] ?? '',
                ];
            }
            $goddessArea['goddess_info'] = [
                'title' => $goddessInfo['title2'] ?? '',
                'avatar' => $goddessInfo['avatar'] ?? '',
                'lucky_planet_switch' => true,
                'lucky_need_auth' => $luckyNeedAuth
            ];
        }

        return show(config('code.success'), '专区信息', $goddessArea);
    }
}
